//
//  SISSUploadPictureViewController.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/10/25.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSUploadPictureViewController.h"
#import "SISSTitleView.h"
#import "SISSUploadImageView.h"
#import "SISSNetworkingManager+HouseProgress.h"

@interface SISSUploadPictureViewController ()
@property (weak, nonatomic) SISSTitleView *titleView;
@property (weak, nonatomic) SISSUploadImageView *uploadImageView;

// 确定
@property (weak, nonatomic) UIButton *confirmButton;


@end

@implementation SISSUploadPictureViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleView.titleStr = titleStr;
}




// 确定按钮点击事件
- (void)confirmButtonClickAction {
    if (!self.uploadImageView.images || self.uploadImageView.images.count == 0) {
        [SISSTools showSVWithTitle:@"请选择图片"];
        return;
    }
    if (self.isBusinessNotaryIn) {
        [kNetworkNoUTF8Manager insertBusinessContractNotaryInfoFileWithID:self.ID images:self.uploadImageView.images success:^(id responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                if (self.selectedImagesBlock) {
                    self.selectedImagesBlock(self.uploadImageView.images);
                }
                [self.navigationController popViewControllerAnimated:YES];
            }
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    } else {
        [kNetworkNoUTF8Manager insertNotaryInfoFileWithID:self.ID images:self.uploadImageView.images success:^(id responseObject) {
            if ([responseObject[@"code"] integerValue] == 200) {
                if (self.selectedImagesBlock) {
                    self.selectedImagesBlock(self.uploadImageView.images);
                }
                [self.navigationController popViewControllerAnimated:YES];
            }
        } failed:^(NSError *error) {
            NSLog(@"%@",error);
        }];
    }
    
}



- (void)setupSubviews {
    [super setupSubviews];
    
    SISSTitleView *titleView = [[SISSTitleView alloc] init];
    titleView.titleStr = @"上传公证书";
    [self.view addSubview:titleView];
    self.titleView = titleView;
    
    SISSUploadImageView *uploadImageView = [[SISSUploadImageView alloc] init];
    uploadImageView.isHiddenTitle = YES;
    [self.view addSubview:uploadImageView];
    self.uploadImageView = uploadImageView;
    
    UIButton *confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [confirmButton setTitle:@"确定" forState:UIControlStateNormal];
    [confirmButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [confirmButton setBackgroundColor:MAIN_COLOR];
    [confirmButton addTarget:self action:@selector(confirmButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    confirmButton.layer.cornerRadius = 4;
    confirmButton.layer.masksToBounds = YES;
    [self.view addSubview:confirmButton];
    self.confirmButton = confirmButton;
}

- (void)initConstraint {
    [super initConstraint];
    
    WeakSelf;
    CGSize buttonSize = CGSizeMake(SCREEN_WIDTH * 0.6, 40);
    [self.titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.view);
        make.left.right.equalTo(weakSelf.view);
        make.height.mas_equalTo(5 * globelMargin);
    }];
    
    [self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.titleView.mas_bottom).offset(2 * globelMargin);
        make.left.right.equalTo(weakSelf.view);
    }];
    
    [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(weakSelf.uploadImageView.mas_bottom).offset(8 * globelMargin);
        make.centerX.equalTo(weakSelf.view.mas_centerX);
        make.size.mas_equalTo(buttonSize);
    }];
    
}

@end
